import { http } from "@/utils/http";
import type {
  RequestResponse,
  KnowledgeBaseData,
  KnowledgeDocument,
  DeleteDocumentData
} from "./types";

export const knowledgeApi = {
  // 获取默认知识库信息
  getDefaultKnowledge: () => {
    return http.request<RequestResponse<KnowledgeBaseData>>(
      "get",
      "/api/v1/knowledgebase/default-collection"
    );
  },
  // 获取知识库文档列表
  getKnowledgeDocumentList: () => {
    return http.request<RequestResponse<KnowledgeDocument[]>>(
      "get",
      "/api/v1/hdl-ai/knowledgebase/documents"
    );
  },
  // 上传知识库文档
  postKnowledgeDocument: (data: { tos_path: string }) => {
    return http.request<RequestResponse<any>>(
      "post",
      "/api/v1/hdl-ai/knowledgebase/documents/upload",
      { params: data }
    );
  },
  // 批量上传知识库文档
  postKnowledgeDocuments: (data: string[]) => {
    return http.request<RequestResponse<any>>(
      "post",
      "/api/v1/hdl-ai/knowledgebase/documents/batch-upload",
      { data }
    );
  },
  // 获取上传文件的预签名URL
  presignedApi: data => {
    return http.request<any>(
      "post",
      "/api/v1/hdl/common/download/presigned-url",
      {
        data
      }
    );
  },
  // 删除知识库文档
  deleteKnowledgeDocument: (doc_id: string) => {
    return http.request<RequestResponse<DeleteDocumentData>>(
      "delete",
      `/api/v1/hdl-ai/knowledgebase/documents/${doc_id}`
    );
  }
};
